home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: dd.chalmers.se!news.chalmers.se!sunic!EU.net!sun4nl!sci.kun.nl!polder!rhialto
- From: rhialto@polder.ubc.kun.nl (Olaf Seibert)
- Subject: Re: Using Message Ports in C, and in Pascal...
- Message-ID: <rhialto.763123144@polder.ubc.kun.nl>
- Sender: news@sci.kun.nl (News owner)
- Nntp-Posting-Host: polder.ubc.kun.nl
- Organisation: Polderland Language & Speech Technology
- Organization: University of Nijmegen, The Netherlands
- References: <2klupi$3h5@canopus.cc.umanitoba.ca> <k+Mqu*7tc@peti.GUN.de>
- Date: Tue, 8 Mar 1994 10:39:04 GMT
- Lines: 43
-
- In <k+Mqu*7tc@peti.GUN.de> simons@peti.GUN.de (Peter Simons) writes:
- >The reason is that PutMsg() and other routines exptect a pointer to a
- >'Message' structure as parameter, which is just the node header to
- >chain them in a list, a pointer to the reply port and the length of
- >the message. Obviously, the length specifies how many byte of actual
- >data are appended. Now, most programmer define their own structure
- >which is a usual 'Message' plus the to-be-sent data and send this
- >structure off.
- >
- >You do not really need to typecast the structure, but otherwise your
- >compiler would complain because he expects a pointer to 'Message' and
- >not to 'whateverMessage'. In fact, it doesn't make a difference for
- >the routine it's just common practise to cast in such situations.
-
- In fact, there is a slightly different solution, that is on average
- about the same amount of typing, but somewhat cleaner.
-
- Suppose you have
-
- struct MyMsg {
- struct Message msg;
- int data;
- } *mymsg;
-
- and you want to PutMsg() it. Now you could do
-
- PutMsg((struct Message *)mymsg, ...);
-
- but also
-
- PutMsg(&mymsg->msg, ...);
-
- This lets the compiler check the types better, because there is no
- cast. This solution works for almost all AmigaOS structures; the
- most annoying ones that don't work are MinList vs. List and MinNode
- vs. Node. These are interchangable for most List manipulating functions,
- yet the types are different.
-
- > bye, Peter
- -Olaf.
- --
- ___ Olaf 'Rhialto' Seibert D787B44DFC896063 4CBB95A5BD1DAA96
- \X/ There are no lemurs in this post rhialto@polder.ubc.kun.nl
-